package com.andnnl.allocator;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by chenss on 2023/12/20.
 */
public class MinTest {

    public static void main(String[] args) {
        List<ReSendCalcRatioBean> list = new ArrayList<>();
        list.add(new ReSendCalcRatioBean("GW1", 30));
        list.add(new ReSendCalcRatioBean("GW2", 10));
        list.add(new ReSendCalcRatioBean("GW3", 20));

        Optional<ReSendCalcRatioBean> minRatioBean = list.stream().filter(bean -> bean.getProportion() > 0)
                .min(Comparator.comparingInt(ReSendCalcRatioBean::getProportion));
        minRatioBean.ifPresent(bean -> System.out.println("Minimum ratio bean: " + bean.getGwNum() + ", " + bean.getProportion()));

        ReSendCalcRatioBean bean = list.stream()
                .min((a,b)->a.getProportion() - b.getProportion()).orElse(null);
        if(bean!= null)
            System.out.println("Minimum ratio bean: " + bean.getGwNum() + ", " + bean.getProportion());

    }

}
class ReSendCalcRatioBean {
    String gwNum; // 网关号
    int proportion; // 比例
    AtomicInteger count = new AtomicInteger(0);//当前计数
    public ReSendCalcRatioBean(String gwNum, int proportion) {
        this.gwNum = gwNum;
        this.proportion = proportion;
    }

    public String getGwNum() {
        return gwNum;
    }

    public int getProportion() {
        return proportion;
    }
}
